﻿@using ExampleWebApplication.Controllers
@using ExampleWebApplication.Models
@using ExampleWebApplication.Properties
<h2>
    @NHibernateStrings.Example7d2
</h2>
<h3>
    <a target="_blank" href="http://demos.telerik.com/aspnet-mvc/razor/grid/aggregatesajax">
        Telerik demo version</a>
</h3>
@(Html.Telerik().Grid<ProductModel>().Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(x => x.ProductName)
                .Aggregate(aggregates => aggregates.Count())
                .ClientGroupFooterTemplate("Count: <#= Count #>")
                .ClientFooterTemplate("Total Count: <#= Count #>");

            columns.Bound(x => x.ViewModelProp)
                .Aggregate(aggregates => aggregates.Count())
                .ClientGroupFooterTemplate("Count: <#= Count #>")
                .ClientFooterTemplate("Total Count: <#= Count #>");

            columns.Bound(o => o.UnitPrice)
                .Width(200)
                .Aggregate(aggreages => aggreages.Sum())
                .Format("{0:c}")
                .ClientGroupFooterTemplate("Sum: <#= $.telerik.formatString('{0:c}', Sum) #>")
                .ClientFooterTemplate("Total Sum: <#= $.telerik.formatString('{0:c}', Sum) #>");

            columns.Bound(o => o.Units_OnOrder)
                .Width(200)
                .Aggregate(aggregates => aggregates.Average())
                .ClientGroupFooterTemplate("Average: <#= Average #>")
                .ClientFooterTemplate("Average: <#= Average #>");

            columns.Bound(o => o.UnitsInStock)
                .Width(100)
                .Aggregate(aggregates => aggregates.Count().Min().Max())
                .ClientGroupHeaderTemplate("<#= Title #>: <#= Key #> (Count: <#= Count #>)")
                .ClientFooterTemplate("<div>Min: <#= Min #></div>" + "<div>Max: <#= Max #></div>");
        })
        .EnableCustomBinding(true).Sortable().Filterable().Pageable()
        .DataBinding(dataBinding => dataBinding.Ajax().Select<NHibernateController>(ctr => ctr.AggregatesClientSideNHibernateData(null)))
        .Groupable(settings => settings.Groups(groups => groups.Add(o => o.UnitsInStock)).Visible(false)))
